package ro.k;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import ro.k.tags.ComandaManopera;
import ro.k.tags.DBManopera;
import ro.k.web.beans.KBeanUtils;
import ro.k.web.beans.order.ManoperaBaseBean;
import ro.k.web.beans.order.ReqManoperaBean;

public class TagsService {

	
	private List<ManoperaBaseBean> manComanda = new ArrayList<ManoperaBaseBean>();
	private List<ReqManoperaBean> reqMan = new ArrayList<ReqManoperaBean>();
	
	
	private DBManopera dbManopera = new DBManopera();
	private ComandaManopera cmdManopera = new ComandaManopera();
	
	public TagsService() {
	}	
	
	public DBManopera getDbManopera() {
		return dbManopera;
	}
	
	public void newAdd(Object obj) {
		if (KBeanUtils.isEmpty(obj)) {
			return;
		}

		String code = obj.toString();
		for (ManoperaBaseBean mb : dbManopera.getManopera()) {
			if (mb.getCod().equals(code)) {
				cmdManopera.getManComanda().add(mb.clone());
			}
		}
	}

	class CompareName implements Comparator<ManoperaBaseBean> {
		@Override
		public int compare(ManoperaBaseBean o1, ManoperaBaseBean o2) {
			return o1.getNume().compareTo(o2.getNume());
		}
	}

	class CompareCode implements Comparator<ManoperaBaseBean> {
		@Override
		public int compare(ManoperaBaseBean o1, ManoperaBaseBean o2) {
			return o1.getCod().compareTo(o2.getCod());
		}
	}

	public void updateManoperaComanda(String code, Double cant) {
		for (ManoperaBaseBean mb : manComanda) {
			if (mb.getCod().equals(code)) {
				mb.setCant(cant);
				mb.setTotal(Double.parseDouble(mb.getValoare()) * cant);
			}
		}
	}

	

	

	// ------------------ Req man ----------------
	public List<ReqManoperaBean> getReqMan() {
		return reqMan;
	}

	public void addReqMan(ReqManoperaBean reqm) {
		reqMan.add(reqm);
	}

	public Double getReqManValoare() {
		Double val = 0.0;
		for (ReqManoperaBean r : reqMan) {
			val += r.getValoare();
		}
		return val;
	}

	public Double getReqManDurata() {
		Double d = 0.0;
		for (ReqManoperaBean r : reqMan) {
			d += r.getDurata();
		}
		return d;
	}

	// ------------------ End Req man ------------
	
}
